/*
 * Fim.java
 *
 * Created on 23 de Maio de 2007, 16:32
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package qvoipm.dados;

import java.nio.ByteBuffer;
import java.util.Date;

/**
 *
 * @author rodrigo
 */
public class Fim extends Pacote {
    
    public static final byte ID = 4;
    public static final int SIZE = Integer.SIZE/Byte.SIZE + Long.SIZE/Byte.SIZE;
    
    private int chamada;       
    private Date dataHora;
    
    public Fim() {
	
    }
    
    public Fim(byte bytes[], boolean withID) {
	super(bytes, withID);
    }
    
    protected void fromBytes(ByteBuffer buffer) {
	setChamada(buffer.getInt());
	if (dataHora != null)	    
	    dataHora.setTime(buffer.getLong());
	else
	    dataHora = new Date(buffer.getLong());
    }
    
    public byte getID() {
	return ID;
    }
    
    public int getTamanho() {
	return SIZE;
    }
    
    protected void writeBytes(ByteBuffer buffer) {
	
	buffer.putInt(getChamada());
	buffer.putLong(getDataHora().getTime());
    }
    
    public int getChamada() {
	return chamada;
    }
    
    public void setChamada(int chamada) {
	this.chamada = chamada;
    }
    
    public Date getDataHora() {
	return dataHora;
    }
    
    public void setDataHora(Date dataHora) {
	this.dataHora = dataHora;
    }
    
}
